package com.tac.service.mes.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.mes.PlannedProductionDao;
import com.tac.dao.mes.PlannedProductionMaterialDao;
import com.tac.pojo.mes.PlannedProduction;
import com.tac.pojo.mes.PlannedProductionMaterial;
import com.tac.service.mes.PlannedProductionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PlannedProductionServiceImpl implements PlannedProductionService {

    @Autowired
    private PlannedProductionDao plannedProductionDao;

    @Autowired
    private PlannedProductionMaterialDao plannedProductionMaterialDao;
    //计划排产查询
    public Result<PageInfo<PlannedProduction>> getList(Integer pageNum, Integer pageSize, String  serialNumber, String planNumber,
                          Integer materialId, Integer bomId, Integer lineId, Integer technologyId,
                          Integer projectMaintenanceId, Date produceDateStart, Date produceDateEnd,
                          Date deliveryDateStart, Date deliveryDateEnd, String status){
        PageHelper.startPage(pageNum,pageSize);
        List<PlannedProduction> list = plannedProductionDao.getList(serialNumber, planNumber, materialId, bomId, lineId, technologyId, projectMaintenanceId, produceDateStart, produceDateEnd
                ,deliveryDateStart, deliveryDateEnd, status);
        PageInfo<PlannedProduction> plannedProductionPageInfo = new PageInfo<>(list);
        return Result.success(plannedProductionPageInfo);
    }
    //计划排产添加
    public Result save(PlannedProduction plannedProduction){
        Integer integer = plannedProductionDao.save(plannedProduction);
        if(integer<=0){
            return Result.error("计划排产添加失败");
        }
        return Result.success(null);
    }
    //计划排产删除
    public Result remove(List<Integer> ids){
        Integer integer = plannedProductionDao.remove(ids);
        if(integer<=0){
            return Result.error("计划排产删除失败");
        }
        return Result.success(null);
    }
    //计划排产更新
    public Result update(PlannedProduction plannedProduction){
        Integer integer = plannedProductionDao.update(plannedProduction);
        if(integer<=0){
            return Result.error("计划排产更新失败");
        }
        return Result.success(null);
    }
    //计划排产物料添加
    public Result save2(PlannedProductionMaterial plannedProductionMaterial){
        Integer integer = plannedProductionMaterialDao.save(plannedProductionMaterial);
        if(integer<=0){
            return Result.error("计划排产物料添加失败");
        }
        return Result.success(null);
    }
    //计划排产物料删除
    public Result remove2(List<Integer> ids){
        Integer integer = plannedProductionMaterialDao.remove(ids);
        if(integer<=0){
            return Result.error("计划排产物料删除失败");
        }
        return Result.success(null);
    }
    //计划排产物料更新
    public Result update2(PlannedProductionMaterial plannedProductionMaterial){
        Integer integer = plannedProductionMaterialDao.update(plannedProductionMaterial);
        if(integer<=0){
            return Result.error("计划排产物料更新失败");
        }
        return Result.success(null);
    }
}
